

//
//  NSDate+DateExtension.m
//  ceshi
//
//  Created by MB.Lee on 17/1/12.
//  Copyright © 2017年 com.coubi.ii. All rights reserved.
//

#import "NSDate+DateExtension.h"

@implementation NSDate (DateExtension)
+(NSDateComponents *)detaleFromDate:(NSDate *)from{
    NSDate *now = [NSDate date];
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
    return  [calendar components:unit fromDate:from toDate:now options:0];
    
}
-(BOOL)isToday{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay;
    NSDateComponents *selfcmp = [calendar components:unit fromDate:self];
    NSDateComponents *nowcmp = [calendar components:unit fromDate:[NSDate date]];
    
    return selfcmp.year == nowcmp.year && selfcmp.month == nowcmp.month &&selfcmp.day == nowcmp.day;
    
}
-(BOOL)isYesterday{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear |NSCalendarUnitMonth|NSCalendarUnitDay;
    
    NSDateComponents *cmps =[calendar components:unit fromDate:self toDate:[NSDate date] options:0];
    return cmps.year == 0 && cmps.month == 0 && cmps.day == 1;
}
-(BOOL)isThisYear{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear;
    NSInteger nowYear = [calendar component:unit fromDate:[NSDate date]];
    NSInteger selfYear = [calendar component:unit fromDate:self];
    return nowYear == selfYear;
    
}

@end
